// 定义常量
const HOST_URL = 'http://127.0.0.1:3000'
// 获取token
// let token = localStorage.get('token');

// 编写axios请求接口
import axios from 'axios'

// 1.0 发送邮箱验证码
// http://127.0.0.1:3000/email/send
export const sendEmailFunc = (data={})=> {
    // return axios.get(`${HOST_URL}/email/send`,{params: data}).then(response => {return  response.data})
    return axios.get(`${HOST_URL}/email/send`,{params: data}).then(response =>  response.data)
}

// 2.0 匹配邮箱验证码
// http://127.0.0.1:3000/email/verify
export const verifyEmailFunc = (data={})=> {
    return axios.get(`${HOST_URL}/email/verify`,{params: data}).then(response =>  response.data)
}
// 3.0 登录
// 地址：http://127.0.0.1:3000/users/login
// 参数：user_acc（账号   user_pwd（密码）
export const loginFunc = (data={})=>{
    return axios.post(`${HOST_URL}/users/login`, data).then(response =>  response.data)
}

// 4.0 注册
// http://127.0.0.1:3000/users/register
// user_acc（账号   user_pwd（密码） user_nick_name(昵称) code(邮箱验证码)
export const registerFunc = (data={})=>{
    return axios.post(`${HOST_URL}/users/register`, data).then(response =>  response.data)
}
// 5.0邮箱登录
// http://127.0.0.1:3000/users/email_login
export const emailLoginFunc = (data={})=>{
    return axios.post(`${HOST_URL}/users/email_login`, data).then(response =>  response.data)
}
// 6.0 城市列表（所有城市）
// http://127.0.0.1:3000/city/list
export const getCityList = ()=> {
    return axios.get(`${HOST_URL}/city/list`).then(response =>  response.data)
}

// 7.0 城市首字母
// http://127.0.0.1:3000/city/firstcode
export const getCodeList = ()=> {
    return axios.get(`${HOST_URL}/city/firstcode`).then(response =>  response.data)
}
// 8.0 获取热门城市
// http://127.0.0.1:3000/city/hot
export const getHotCityList = ()=> {
    return axios.get(`${HOST_URL}/city/hot`).then(response =>  response.data)
}
// 9.0 获取轮播图lieb
// http://127.0.0.1:3000/banner/list
export const getBannerList = ()=> {
    return axios.get(`${HOST_URL}/banner/list`).then(response =>  response.data)
}
// 10. 获取导航列表
// http://127.0.0.1:3000/navs/list
export const getNavList = (data={})=> {
    return axios.get(`${HOST_URL}/navs/list`,{params: data}).then(response =>  response.data)
}
// 11. 根据导航获取文章列表
// http://127.0.0.1:3000/article/nav
export const getNavArticleList = (data={})=> {
    return axios.get(`${HOST_URL}/article/nav`,{params: data}).then(response =>  response.data)
}
// 12. 关键字搜索文章
// http://127.0.0.1:3000/article/search
export const getSearchArticleList = (data={})=> {
    return axios.get(`${HOST_URL}/article/search`,{params: data}).then(response =>  response.data)
}

// 12. 根据地址获取文章（模糊查询）
// http://127.0.0.1:3000/article/address
export const getAddressArticleList = (data={})=> {
    return axios.get(`${HOST_URL}/article/address`,{params: data}).then(response =>  response.data)
}

// 13. 获取全部分类的文章
// http://127.0.0.1:3000/article/list
export const getArticleList = (data={})=> {
    return axios.get(`${HOST_URL}/article/list`,{params: data}).then(response =>  response.data)
}

// 14. 获取文章详情
// http://127.0.0.1:3000/article/detail
export const getArticleDetail = (data={})=> {
    return axios.get(`${HOST_URL}/article/detail`,{params: data}).then(response =>  response.data)
}

// 15. 判断用户登录状态
// http://127.0.0.1:3000/users/online
export const isOnLine = ()=> {
    return axios.get(`${HOST_URL}/users/online`,{headers: {token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}

// 16. 收藏文章
// http://127.0.0.1:3000/like/add
export const addLikeFuc = (data={})=> {
    return axios.post(`${HOST_URL}/like/add`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 17. 取消收藏
// http://127.0.0.1:3000/like/remove
export const removeLikeFuc = (data={})=> {
    return axios.post(`${HOST_URL}/like/remove`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}

// 18. 查看收藏
// http://127.0.0.1:3000/like/detail
export const detailLikeFuc = (data={})=> {
    return axios.post(`${HOST_URL}/like/detail`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}

// 19. 收藏列表
// http://127.0.0.1:3000/like/list
export const listLikeFuc = (data={})=> {
    return axios.post(`${HOST_URL}/like/list`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}

// 20. 发表评论
// http://127.0.0.1:3000/comment/add
export const addCommentFunc = (data={})=> {
    return axios.post(`${HOST_URL}/comment/add`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 21. 获取评论列表
// http://127.0.0.1:3000/comment/list
export const getCommentList = (data={})=> {
    return axios.get(`${HOST_URL}/comment/list`,{params: data,headers: {token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 22. 获取用户头像 (token)
// http://127.0.0.1:3000/users/get_picUrl
export const getUserPicUrl = (data={})=> {
    return axios.get(`${HOST_URL}/users/get_picUrl`,{params: data,headers: {token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}

// 23. 获取评论列表中的用户头像 (user_id)
// http://127.0.0.1:3000 /users/get_img
export const getUserImage= (data={})=> {
    return axios.get(`${HOST_URL}/users/get_img`,{params: data,headers: {token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 24. 获取用户资料
// http://127.0.0.1:3000/users/get_user_info
export const getUserInfo = (data={})=> {
    return axios.get(`${HOST_URL}/users/get_user_info`,{params: data,headers: {token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 25. 设置用户头像
// http://127.0.0.1:3000/users/set_picUrl
export const setUserPicUrl = (data={})=> {
    return axios.post(`${HOST_URL}/users/set_picUrl`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 26. 上传图片
// http://127.0.0.1:3000/photo/preview
export const uploadPhotoFunc = (data={})=> {
    return axios.post(`${HOST_URL}/photo/preview`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 27. 删除图片
// http://127.0.0.1:3000/photo/delete
export const removePhotoFunc = (data={})=> {
    return axios.post(`${HOST_URL}/photo/delete`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 28. 设置用户资料
// http://127.0.0.1:3000/users/set_user_info
// user_nick_name(昵称)  user_sex（性别） user_age（年龄） user_address（地址）
export const setUserInfo = (data={})=> {
    return axios.post(`${HOST_URL}/users/set_user_info`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 29. 收藏列表
// http://127.0.0.1:3000/like/list
export const getLikeList = (data={})=> {
    return axios.post(`${HOST_URL}/like/list`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}
// 30. 删除账号
// http://127.0.0.1:3000/users/remove
export const removeUserFunc = (data={}) => {
    return axios.post(`${HOST_URL}/users/remove`,data, {headers:{token: localStorage.getItem('auto_token')}}).then(response =>  response.data)
}